class Stack {
  constructor () {
    this.dataStore = []
    this.top = 0
  }

  /**
   * 压入元素
   */
  push (element) {
    this.dataStore[this.top++] = element
  }

  /**
   *  弹出元素
   * @returns {*}
   */
  pop () {
    return this.dataStore[--this.top]
  }

  /**
   *  返回栈顶元素
   * @returns {*}
   */
  peek () {
    return this.dataStore[this.top - 1]
  }

  /**
   *  返回长度
   * @returns {number}
   */
  length () {
    return this.top
  }

  /**
   * 清空
   */
  clear () {
    this.top = 0
    this.dataStore = []
  }

}

function print (ele) {
  console.log(ele)
}

var s = new Stack()
s.push('David')
s.push('Raymond')
s.push('Bryan')
print('length: ' + s.length())
print(s.peek())
var popped = s.pop()
print('The popped element is: ' + popped)
print(s.peek())
s.push('Cynthia')
print(s.peek())
s.clear()
print('length: ' + s.length())
print(s.peek())
s.push('Clayton')
print(s.peek())
